#ifndef OCEAN_VAGSDK_VAGSDK_UTIL_H
#define OCEAN_VAGSDK_VAGSDK_UTIL_H

#include <jni.h>
#include "jni_util.h"
#include "dauSproxy.h"

#define THROW_VAG_EX(env, msg)          \
    do {                                \
        (env)->ThrowNew((JNIHandle::GetInstance()->cls_vagApi_ex), (msg));     \
    } while(0)

#define CHECK_CODE_THROW_VAG_EX(env, code, msg) \
    do {                                        \
        if ((code) < 0) {                       \
           THROW_VAG_EX(env, msg);                                     \
        }           \
    } while(0)

#define CHECK_NULL_RETURN_THROW_API_EX(env, x, msg, rs)    \
    do {                                                       \
        if ((x) == nullptr) {                                  \
            THROW_VAG_EX(env, msg);              \
            return (rs);                                         \
        }                                                      \
    } while(0)

#define CHECK_NULL_RETURN_THROW_API_EX_AND_DELETE_REF(env, x, msg, rs, jobj)    \
    do {                                                       \
        if ((x) == nullptr) {                                               \
            (env)->DeleteLocalRef((jobj));         \
            THROW_VAG_EX(env, msg);              \
            return (rs);                                         \
        }                                                      \
    } while(0)

#define CHECK_NULL_RETURN_THROW_API_EX_AND_DELETE_REF2(env, x, msg, rs, jobj1, jobj2)    \
    do {                                                       \
        if ((x) == nullptr) {                                               \
            (env)->DeleteLocalRef((jobj1));                                              \
            (env)->DeleteLocalRef((jobj2));                            \
            THROW_VAG_EX(env, msg);              \
            return (rs);                                         \
        }                                                      \
    } while(0)

#define CHECK_NULL_RETURN_THROW_API_EX_AND_DELETE_REF3(env, x, msg, rs, jobj1, jobj2, jobj3)    \
    do {                                                       \
        if ((x) == nullptr) {                                               \
            (env)->DeleteLocalRef((jobj1));                                              \
            (env)->DeleteLocalRef((jobj2));                                                     \
            (env)->DeleteLocalRef((jobj3));                 \
            THROW_VAG_EX(env, msg);              \
            return (rs);                                         \
        }                                                      \
    } while(0)

#define RETURN_V_IF_FALSE(rs, returnValue)    \
    do{                          \
         if (!((rs).isSuccess)) {   \
            return (returnValue);   \
         }                      \
    } while(0)

#define RETURN_IF_FALSE(rs)    \
    do{                          \
         if (!((rs).isSuccess)) {   \
            return; \
         }                      \
    } while(0)
struct ParseServerDevInfoPlus {
    _server_dev_info_plus info{};
};

struct ParseChannelMediaInfoPlus {
    _channel_media_info_plus info{};
};

ParseServerDevInfoPlus ParseServerDevInfo(JNIEnv *env, jobject serverDevInfoPlus);

ParseServerDevInfoPlus ParseServerDevInfoUpdate(JNIEnv *env, jobject serverDevInfoPlus);

ParseChannelMediaInfoPlus ParseChannelMediaInfo(JNIEnv *env, jobject channelMediaInfoPlus);

//PTZ 回调入参，从C结构体转换为jobject对象
jobject ConvertsPtzParam(JNIEnv *env, _PTZ_param_DAU *ptzParam);

// RecInfoDAU 参数转换函数
jobject ConvertsRecInfoDAU(JNIEnv *env, _Rec_Info_DAU *recInfo);

jobject ConvertsRecSearchEventInfo(JNIEnv* env, void* _Rec_reserve_info);

jobject ConvertsRecSearchInfo(JNIEnv* env, void* _Rec_reserve_info);

void convertToRecSearchInfo(JNIEnv* env, jobject Res, void* _Rec_reserve_info);

void ConvertsRecSearchEventInfo(JNIEnv* env, jobject Res, void* _Rec_reserve_info);

void ConvertsRecUrlInfo(JNIEnv* env, jobject Res, void* _Rec_reserve_info);

//PTZ 回调出参(应答)，从jobject对象转换为C结构体
void ParsePtzResponse(JNIEnv *env, jobject ptzResponse, _PTZ_RESPONSE_DAU* res);

#endif //OCEAN_VAGSDK_VAGSDK_UTIL_H
